{% extends "base.html" %}

{% block title %}Organizations - {{ block.super }}{% endblock %}
{% block navbar_title%}Organizations{% endblock %}

{% block content %}

<section class="content">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            {% include "messages.html" %}

            <div class="callout callout-info">
                {% if not memberships %}
                <p>You need an organization to manage your projects and their subscriptions. Click <a href="{% url 'create_organization' %}">here</a> to create your organization.</p>
                {% else %}
                <p>The organizations allows you to manage your projects and subscriptions. <a href="{% url 'create_organization' %}">Create a new organization?</a></p>
                {% endif %}
            </div>

            <div class="box box-primary">
                <div class="box-body table-responsive no-padding">
                    <table class="table table-hover table-striped" id="table-organizations">
                        <tbody>
                        <tr>
                            <th>Name</th>
                            <th>Role</th>
                            <th></th>
                        </tr>
                        {% for membership in memberships %}
                        <tr>
                            <td>{{ membership.organization.name }}</td>
                            <td>{{ membership.role }}</td>
                            <td class="pull-right">
                                <div class="btn-group" role="group">
                                    {% if membership.is_invited %}
                                    <a href="{% url 'accept_organization_invitation' org_name=membership.organization.name key=membership.key %}" class="btn btn-primary btn-xs" type="button">Accept Invitation</a>
                                    {% endif %}
                                    {% if membership.is_owner and not membership.is_invited %}
                                    <a href="{% url 'edit_organization' org_name=membership.organization.name %}" class="btn btn-default btn-xs">Edit</a>
                                    <a href="{% url 'delete_organization' org_name=membership.organization.name %}" class="btn btn-danger btn-xs" type="button">Delete</a>
                                    {% endif %}
                                </div>
                            </td>
                        </tr>
                        {% empty %}
                        <tr>
                            <td colspan="2">No organization yet</td>
                        </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>

{% endblock %}
